﻿package net.jmp0.toast.entities.menu 
{
	import net.jmp0.toast.entities.bases.GameButton;
	import net.jmp0.toast.entities.effects.GameText;
	import punk.Actor;
	
	/**
	 * ...
	 * @author Thodd
	 */
	public class CharSelector extends Actor
	{
		
		private var upButton:UpButton;
		
		private var downButton:DownButton;
		
		private var choosenChar:int = 0;
		
		private var alphabet:String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		
		public var charText:GameText;

		public function CharSelector(x:int, y:int) {
			this.x = x;
			this.y = y;
		
			this.upButton = new UpButton(x-15, y-40, upButtonWasPressed);
			
			charText = new GameText(alphabet.charAt(choosenChar), x, y, "garbage", 100, -100, true);
			charText.color = 0x800000;
			
			this.downButton = new DownButton(x-10, y + 120, downButtonWasPressed);
			
			FP.world.add(this);
		}
		
		
		public function upButtonWasPressed(caller:GameButton):void {
			choosenChar = (choosenChar + 1) % alphabet.length;
			charText.text = alphabet.charAt(choosenChar);
		}
		
		public function downButtonWasPressed(caller:GameButton):void {
			choosenChar = choosenChar - 1;
			choosenChar = (choosenChar < 0) ? (alphabet.length-1) : choosenChar;
			charText.text = alphabet.charAt(choosenChar);
		}
		
		
		public function destroy():void {
			upButton.destroy();
			downButton.destroy();
			charText.destroy();
			FP.world.remove(this);
		}
		
	}

}